package com.example.demo.service.handler;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.util.HttpUtil;
import com.example.demo.util.SendChatRot;
import com.example.demo.util.XMLUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class WxTextMessage extends WxMessageAbstractHandler {
    private Logger logger = LoggerFactory.getLogger(WxTextMessage.class);

    @Override
    public String handlerMessage(Map<String, String> map) {
        String message = map.get("Content");
        logger.info("收到消息：" + message);
        //将消息插入日志表
        String serviceId = map.get("ToUserName");
        String openID = map.get("FromUserName");
        //pass
        //返回消息
        map.clear();
        map.put("ToUserName", openID);
        map.put("FromUserName", serviceId);
        map.put("MsgType", "text");
//        String tulingUrl = wxUserService.getWxConfig().getTulingUrl();
//        String apikey = wxUserService.getWxConfig().getTulingApikey();
//        String content = SendChatRot.tulingMessage(tulingUrl, apikey, message, openID);
        String url = wxUserService.getWxConfig().getQingyunkeUrl();
        String content = SendChatRot.qingyunkeMessage(url, message);
        if (content == null || "".equals(content)) {
            return "success";
        }
        map.put("Content", content);
        String result = XMLUtil.createXmlStr(map);
        return result;
    }


}
